package com.ywj.chatroom.multiroom.server.handler;

import com.ywj.chatroom.multiroom.message.GroupMembersRequestMessage;
import com.ywj.chatroom.multiroom.server.session.GroupSessionFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.List;

/**
 * 查看群成员消息处理器
 * 1.获取群聊名字     2.获取到所有成员的channel
 * 3.通过channel找到对应的名字
 */
@ChannelHandler.Sharable
public class GroupMembersRequestMessageHandler extends SimpleChannelInboundHandler<GroupMembersRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GroupMembersRequestMessage msg) throws Exception {
        String groupName = msg.getGroupName();
        //获取成员
        List<String> users = GroupSessionFactory.getGroupSession().getUsers(groupName);
        ctx.channel().writeAndFlush("组" + groupName + "的成员是：" + users.toString());
    }
}
